package site.yunnong.atvris.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import site.yunnong.atvris.dao.common.api.CommonResult;
import site.yunnong.atvris.dao.common.api.YunnongHttpStatus;
import site.yunnong.atvris.dao.common.util.LocalAssert;
import site.yunnong.atvris.dao.portal.service.UmsUserManageService;

/**
 * @author JinghaoZhang
 * @date 2021年-04月-07日
 */
@Slf4j
@Api(tags = "个人用户管理")
@RestController
@RequestMapping("/account")
public class UmsUserManageController {

    @Autowired
    private UmsUserManageService umsUserManageService;

    @ApiOperation("获取我的用户信息")
    @GetMapping("/info")
    public CommonResult info() {
        // todo
//        UserVo userVo = userManageService.getCurrentUserDto();
//        return CommonResult.result(userVo, YunnongHttpStatus.SUCCESS);
        return null;
    }

    @ApiOperation("修改用户个性签名")
    @PatchMapping("/personalSign")
    public CommonResult updatePersonalSign(@RequestParam("personalSign") String personalSign) {
        int count = umsUserManageService.updateUserPersonalSign(personalSign);
        if (count > 0) {
            return CommonResult.result(YunnongHttpStatus.NO_CONTENT);
        }
        return CommonResult.result(YunnongHttpStatus.FAILED);
    }

    @ApiOperation("修改用户昵称")
    @PatchMapping("/nickname")
    public CommonResult updateNickname(@RequestParam("nickname") String nickname) {
        int count = umsUserManageService.updateUserNickname(nickname);
        LocalAssert.notZero(count, "修改用户昵称失败");
        return CommonResult.result(YunnongHttpStatus.NO_CONTENT);
    }

    @ApiOperation("新增用户兴趣")
    @PutMapping("/interest")
    public CommonResult updateInterest(Long partitionId) {
        int count = umsUserManageService.updateUserInterest(partitionId);
        if (count > 0) {
          return CommonResult.result(YunnongHttpStatus.NO_CONTENT);
        }
        return CommonResult.result(YunnongHttpStatus.FAILED);
    }

    @ApiOperation("删除用户兴趣")
    @DeleteMapping("/interest")
    public CommonResult deleteInterest(Long partitionId) {
        int count = umsUserManageService.deleteUserInterest(partitionId);
        if (count > 0) {
            return CommonResult.result(YunnongHttpStatus.NO_CONTENT);
        }
        return CommonResult.result(YunnongHttpStatus.SUCCESS, "该用户未添加此兴趣标签");
    }

//    @ApiOperation("获取用户兴趣")
//    @GetMapping("/interests")
//    public CommonResult interests() {
//        List<UserInterestTag> interests = userManageService.getUserInterests();
//        if (CollectionUtils.isEmpty(interests)) {
//            return CommonResult.result(YunnongHttpStatus.NO_CONTENT);
//        }
//        return CommonResult.result(interests, YunnongHttpStatus.SUCCESS);
//    }
}
